class Solution {
public:
    int calculate(string s) {
        char op='+';
        int i=0,n=s.size();
        vector<int> st;
        while(i<n)
        {
            if(s[i]==' ')i++;
            else if(s[i]>='0'&&s[i]<='9')
            {
                int tmp=0;
                while(s[i]>='0'&&s[i]<='9'&&i<n)
                {
                    tmp=tmp*10+(s[i++]-'0');
                }
                if(op=='+')st.push_back(tmp);
                else if(op=='-')st.push_back(-tmp);
                else if(op=='*')st.back()*=tmp;
                else if(op=='/')st.back()/=tmp;
            }
            else op=s[i++];
        }
        int ret=0;
        for(auto x:st)ret+=x;
        return ret;
    }
};
